/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.vo;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.common.utils.validation.constraints.DatePattern;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.entity.MaintainPartsWork;
import org.springblade.modules.admin.entity.MaintainPlanContent;
import org.springblade.modules.admin.enums.EmerProcTypeEnum;
import org.springblade.modules.admin.enums.MaintainPlanContentEnum;
import org.springblade.modules.admin.enums.WorkOrderTypeEnum;
import org.springblade.modules.admin.vo.plan.PlanUserSignDetailVo;
import org.springblade.modules.admin.wrapper.MaintainPlanContentWrapper;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 视图实体类
 *
 * @author ysq
 * @since 2022-06-28
 */
@Data
@ApiModel(value = "SparepartPricesVO对象", description = "SparepartPricesVO对象")
public class SparepartPricesVO {


	@ApiModelProperty("当前记录id")
	private Long id;

	@ApiModelProperty("维修记录id,用户判断是否能批量审核")
	private Long parentPlanId;
	private Long workHistoryId;

	@ApiModelProperty("项目名称")
	private String buildingName;

	@ApiModelProperty("电梯地址")
	private String elevatorAddress;

	@ApiModelProperty("工单id")
	private Long planId;

	@ApiModelProperty("申请人")
	private String createUserName;

	@ApiModelProperty("配件名称")
	private String partName;

	@ApiModelProperty("层站id")
	private String floorStandIds;

	@ApiModelProperty("层站名称")
	private String floorStandNames;

	@ApiModelProperty("配件编号")
	private String partNO;

	@ApiModelProperty("配件数量")
	private String partNum;

	@ApiModelProperty("部件关联的类目id")
	private Long categoryId;

	@ApiModelProperty("部件关联的skuId")
	private Long skuId;

	@ApiModelProperty("关联sku配件信息")
	private JSONObject skuPartsInfo;

	@ApiModelProperty("配件信息")
	private String partsInfo;

	@ApiModelProperty("申请时间")
	private String createTime;


	@ApiModelProperty("上级审批时间")
	private String parentCheckTime;

	@ApiModelProperty("报价员审批时间")
	private String priceCheckTime;

	@ApiModelProperty("报价员名称")
	private String priceUserName;

	@ApiModelProperty("报价状态0:未报价，1：已报价,2:待报价")
	private Integer priceStatus = 2;

	@ApiModelProperty("仓库审核状态仓库审核状态 0:未通过1：已通过, 2待审核")
	private Integer warehouseStatus = 2;

	@ApiModelProperty("仓库员名称")
	private String warehouseUserName;

	@ApiModelProperty("仓管审核时间")
	private String warehouseCreateTime;

	@ApiModelProperty("总价")
	private String allPrice;

	@ApiModelProperty("转审时间")
	private String transferTime;

	@ApiModelProperty("分配时间")
	private String apportionTime;

	@ApiModelProperty("分配人")
	private String userNames;


	private String signInfos;

	private List<String> signUsers;

	private Integer status;

	private String statusName;

	@ApiModelProperty("流程实例id")
	private String processInstanceId;

	private Integer isStop;

	/**
	 * 紧急程度
	 */
	private Integer emerProcType;

	/**
	 * 工单类型
	 */
	private Integer workOrderType;

	/**
	 * 紧急程度描述
	 */
	private String emerProcTypeName;

	/**
	 * 工单类型描述
	 */
	private String workOrderTypeName;

	/**
	 * 2024-05-06 新增 部件id集合
	 */
	private String partsId;

	/**
	 * 2024-05-06 部件id列表
	 */
	private List<Long> partIds;

	/**
	 * 2024-05-31 新增任务类型
	 */
	private String planTypeFullName;

	/**
	 * 2024-05-31 新增sourcePlanType
	 */
	private Integer sourcePlanType;

	/**
	 * 2024-05-31 新增来源完成时间
	 * 仅保留时分秒
	 */
	@JsonFormat(pattern = "yyyy-MM-dd")
	private Date planEndTime;

	/**
	 * 2024-06-03 新增来源类型名
	 */
	private String sourcePlanTypeName;

	private Long elevatorId;

	private Long buildingId;

	@ApiModelProperty(value = "审批状态：1-待审批，2-通过，3-驳回, 4-撤回,5-退回")
	private Integer approveStatus;

	private List<MaintainPartsWork> partsList;

	public void setEmerProcType(Integer emerProcType) {
		if(Func.isNotEmpty(emerProcType)){
			this.emerProcTypeName = EmerProcTypeEnum.getName(emerProcType);
		}
		this.emerProcType = emerProcType;
	}

	public void setWorkOrderType(Integer workOrderType) {
		if(Func.isNotEmpty(workOrderType)){
			this.workOrderTypeName = WorkOrderTypeEnum.getName(workOrderType);
		}
		this.workOrderType = workOrderType;
	}


	public void setParentCheckTime(String parentCheckTime) {
		if (StrUtil.isNotEmpty(parentCheckTime)) {
			final DateTime parse = DateUtil.parse(parentCheckTime, "yyyy-MM-dd HH:mm:ss");
			this.parentCheckTime = DateUtil.format(parse, "yyyy-MM-dd HH:mm:ss");
		}
	}

	public void setStatus(Integer status) {
		this.status = status;
		MaintainPlanContent maintainPlanContent = new MaintainPlanContent();
		maintainPlanContent.setTypeStatus(MaintainPlanContentEnum.MAINTAIN_PARTS.getId());
		maintainPlanContent.setStatus(status);
		this.statusName = MaintainPlanContentWrapper.build().entityVO(maintainPlanContent).getStatusName();
	}

	public void setSignInfos(String signInfos) {
		if (StrUtil.isNotEmpty(signInfos)) {
			signUsers = new ArrayList<>();
			List<PlanUserSignDetailVo> list = new ArrayList<>(16);
			String[] split = signInfos.split("%");
			for (String str : split) {
				PlanUserSignDetailVo planUserSignDetailVo = JSON.parseObject(str, PlanUserSignDetailVo.class);
				if (planUserSignDetailVo.getIsTakePartIn()) {
					signUsers.add(planUserSignDetailVo.getUserName());
				}
				list.add(planUserSignDetailVo);
			}
			if (list.size() > 0) {
				this.userNames = String.join(",", list.stream().map(PlanUserSignDetailVo::getUserName).collect(Collectors.toList()));
			}
		}
		this.signInfos = signInfos;

	}
}
